#include "mainwindow.h"
#include "login.h"
#include <QApplication>
#include <QLocale>
#include <QTranslator>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    login Login;//登录页面
    MainWindow mainServer;//主页面
    QTranslator translator;

    const QStringList uiLanguages = QLocale::system().uiLanguages();
    for (const QString &locale : uiLanguages) {
        const QString baseName = "untitled4_" + QLocale(locale).name();
        if (translator.load(":/i18n/" + baseName)) {
            a.installTranslator(&translator);
            break;
        }
    }

    Login.show();

    QObject::connect(&Login, &login::loginSuccessful, [&](){
        Login.close(); // 关闭登录窗口
        mainServer.setUsername(Login.getUser());
        qDebug() << "Login.getUser() = " <<Login.getUser();
        mainServer.show(); // 显示主窗口
    });

    return a.exec();
}

